<template>
  <div>
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <span class="iconfont header-abs-back">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      景区详情
      <router-link tag="div" to="/" class="header-fixed-back">
        <span class="iconfont fixed-back">&#xe624;</span>
      </router-link>
    </div>
  </div>
</template>

<script>

export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 48 ) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 :opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll',this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll',this.handleScroll)
  }
}

</script>

<style lang="stylus" scoped>
@import '~@/assets/styles/variables.styl'
  .header-abs
    position: absolute
    left: .5rem
    top: .5rem
    width: 2.5rem
    line-height: 2.5rem
    text-align: center
    border-radius: 1.25rem
    background: rgba(0,0,0,.6)
    .header-abs-back
      font-size: 1.5rem
      color: #fff
  .header-fixed
    position: fixed
    top: 0
    right: 0
    left: 0
    line-height: 3rem
    text-align: center
    background: $bgcolor
    color: #fff
    font-size: 1.2rem
    .header-fixed-back
      position: absolute
      left: 0
      top: 0
      width: 3rem
      line-height: 3rem
      .fixed-back
        font-size: 1.5rem
</style>